<?php
namespace Home\Controller;
use \Home\Controller\IndexController;

class OrderController extends IndexController {

    public function add() {
        //传递页值
        $_p = I('get.p') | $_p = I('post.p');
        $p = $_p ? $_p : '1';
        $this->assign('p', $p);
    }

    public function edit() {
        //传递页值
        $_p = I('get.p') | $_p = I('post.p');
        $p = $_p ? $_p : '1';
        $this->assign('p', $p);
    }

    public function delete() {
        //传递页值
        $_p = I('get.p') | $_p = I('post.p');
        $p = $_p ? $_p : '1';
        $this->assign('p', $p);
    }

    public function lst() {
        //传递页值
        $_p = I('get.p') | $_p = I('post.p');
        $p = $_p ? $_p : '1';
        $this->assign('p', $p);

        $id = I('get.id');
        $this->assign('id', $id);
        $model = D('Order');
        $data = $model->search();
        $this->assign(array(
            'data' => $data['data'],
            'page' => $data['page'],
        ));
        //取出客户名字
        $cModel = M('Client');
        $name = $cModel->field('name')->where(array('id' => array('eq', $id)))->find();
        $this->assign($name);

        $this->display();
    }

    public function look() {
        //传递页值
        $_p = I('get.p') | $_p = I('post.p');
        $p = $_p ? $_p : '1';
        $this->assign('p', $p);

        //客户id
        $gid = I('get.gid');
        $this->assign('gid', $gid);
        //订单id
        $id = I('get.id');
        //取出订单和其中商品信息
        $model = D('Order');
        $data = $model->where(array('id' => array('eq', $id)))->find();
        $ogModel = M('OrderGoods');
        $gdata = $ogModel->where(array('order_id' => array('eq', $id)))->select();
        $this->assign(array(
            'data' => $data,
            'gdata' => $gdata,
        ));
        //取出客户名字
        $cModel = M('Client');
        $name = $cModel->field('name')->where(array('id' => array('eq', $gid)))->find();
        $this->assign($name);

        $this->display();
    }

}
